#ifndef EDITOROBJECTLIST_H
#define EDITOROBJECTLIST_H
#include "StompedReality/Core/TypeSystem/TypeSystem.h"
#include "StomperLib/Objects/EditorObjectInfo.h"
#include <Gwen/Controls/Base.h>
#include <functional>
#include <string>
#include <vector>

namespace StomperLib {
class EditorObjectList : Gwen::Controls::Base
{
 protected:

  std::vector<StomperLib::EditorObjectInfo*> m_EditorObjects;
  int m_SelectedObjectIndex;

 public:

  EditorObjectList( Gwen::Controls::Base* base );
  virtual ~EditorObjectList( );
  std::vector<StomperLib::EditorObjectInfo*>::iterator Begin( );
  std::vector<StomperLib::EditorObjectInfo*>::iterator End( );
  int Size( );
  int SelectedObjectIndex( );
  void Clear( );
  int Add( StomperLib::EditorObjectInfo* obj );
  StomperLib::EditorObjectInfo* Remove( int index );
  StomperLib::EditorObjectInfo* SelectObject( int index );

  bool Contains( std::function<bool(StomperLib::EditorObjectInfo*)> compare );
  int FindIndex( std::function<bool(StomperLib::EditorObjectInfo*)> function );
  int Select( std::function<bool(StomperLib::EditorObjectInfo*)> function );

  void UnselectObject( );
  bool IsObjectSelected( );
  int GetSelectedObjectIndex( );

  StomperLib::EditorObjectInfo* Get( int index );

  template <class TYPE>
  TYPE* Get( int index )
  {
    StomperLib::EditorObjectInfo* obj = Get( index );
    if (obj == NULL)
      return NULL;
    return (TYPE*)obj;
  }

  StomperLib::EditorObjectInfo* GetSelectedObject( );
  template <class TYPE>
  TYPE* GetSelectedObject( )
  {
    StomperLib::EditorObjectInfo* obj = GetSelectedObject( );
    if (obj == NULL)
      return NULL;
    return (TYPE*)obj;
  }

  Json::Value EditorObjectList::CreateJson( );
  void ParseJson( Json::Value& root );

 public:

  Gwen::Event::Caller onSelectionChange;

};

}
#endif // ifndef EDITOROBJECTLIST_H